from selenium.webdriver.common.by import By

from page_object.driver.AndroidClient import AndroidClient
import time
from page_object.pages.BasePage import BasePage


class ShopPage(BasePage):
    def getPriceByName(self, name):
        '''
        使用股票名获取股票的价格
        :param name: 股票名称
        :return: 价格
        '''
        # 第一种写法，最基础得
        # price = self.driver.find_element_by_xpath\
        #     ("//*[contains(@resource-id, 'stock_name') and @text='"+name+"']" + "/../..//*[contains(@resource-id, 'column_two')]").text

        # 第二种写法，使用by
        gupiao_price = (By.XPATH, "//*[contains(@resource-id, 'stock_name') and @text='%s']" %name + "/../..//*[contains(@resource-id, 'column_two')]")
        price = self.find(gupiao_price).text

        # price = self.find_by_xpath("//*[contains(@resource-id, 'stock_name') and @text='%s']" %name + "/../..//*[contains(@resource-id, 'column_two')]").text

        return float(price)
    def zuoye(self, name):
        time.sleep(2)
        price = self.driver.find_element_by_xpath("//*[contains(@resource-id, 'index_name') and @text='" + name + "']" + "/..//*[contains(@resource-id, 'index_price')]").text
        print(price)
        return float(price)

